package org.esprit.ocm.server.metier.common;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public interface ICommonServiceAsync<T>
{
 
    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void getDao( AsyncCallback<org.esprit.ocm.server.dao.common.IDao<T>> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void getType( AsyncCallback<java.lang.Class<T>> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void setDao( org.esprit.ocm.server.dao.common.IDao<T> _dao, AsyncCallback<Void> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void add( T _o, AsyncCallback<T> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void save( T _o, AsyncCallback<T> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void remove( java.io.Serializable _id, AsyncCallback<Void> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void remove( T _o, AsyncCallback<Void> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void count( AsyncCallback<java.lang.Integer> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void fetch( AsyncCallback<java.util.List<T>> callback );


    /**
     * GWT-RPC service  asynchronous (client-side) interface
     * @see org.esprit.ocm.server.metier.common.ICommonService
     */
    void findById( java.io.Serializable _id, AsyncCallback<T> callback );


    /**
     * Utility class to get the RPC Async interface from client-side code
     */
    public static final class Util 
    { 
        private static ICommonServiceAsync instance;

        public static final ICommonServiceAsync getInstance()
        {
            if ( instance == null )
            {
                instance = (ICommonServiceAsync) GWT.create( ICommonService.class );
                ServiceDefTarget target = (ServiceDefTarget) instance;
                target.setServiceEntryPoint( GWT.getModuleBaseURL() + "ICommonService" );
            }
            return instance;
        }

        private Util()
        {
            // Utility class should not be instanciated
        }
    }
}
